package com.clss.commandhelper.function.login;


import com.clss.commandhelper.R;
import com.clss.commandhelper.base.BaseCallback;
import com.clss.commandhelper.base.BaseJson;
import com.clss.commandhelper.base.BasePresenter;
import com.clss.commandhelper.base.BaseView;
import com.clss.commandhelper.tools.SpHelper;

/**
 *
 * @author liuv
 * @date 2017/10/26
 */

public class LoginPresenter extends BasePresenter {
    private static final String TAG = "LoginPresenter";

    private LoginView mLoginView;
    private LoginModel mLoginModel;

    public void setLoginView(LoginView loginView) {
        this.mLoginView = loginView;
    }

    public void toLogin(String userName, String password){
        mLoginView.showLoadingDialog(mLoginView.getActContext().getString(R.string.is_loading));
        if (mLoginModel == null){
            mLoginModel = new LoginModel(mLoginView.getActContext());
        }
        mLoginModel.toLogin(userName, password,
                new BaseCallback(mLoginView) {
            @Override
            public void responseSuccess(BaseJson baseJson) {
                LoginBean loginBean = mGson.fromJson(baseJson.getObj(), LoginBean.class);
                SpHelper.getInstance().saveAll(loginBean);
                mLoginView.loginSuccess();
            }
        });
    }

    @Override
    public void cancelCall() {

    }

    public interface LoginView extends BaseView {
        void loginSuccess();
    }

}
